﻿using System;
using Game2DFramework.Extensions;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace MechGame.Utility
{
    class MenuItem
    {
        private Action _action;

        public MenuItem(string text, Action onAction)
        {
            Text = text;
            _action = onAction;
        }

        public string Text { get; private set; }
        public bool IsSelected { get; set; }
        public Rectangle TargetRectangle { get; set; }

        public void InvokeAction()
        {
            _action();
        }

        public void Draw(SpriteBatch spriteBatch, SpriteFont font, float alpha)
        {
            var size = font.MeasureString(Text);
            var startX = TargetRectangle.X + (TargetRectangle.Width - size.X)*0.5f;
            var startY = TargetRectangle.Y + (TargetRectangle.Height - size.Y)*0.5f;
            spriteBatch.DrawString(font, Text, new Vector2(startX + 2, startY + 2).SnapToPixels(), Color.Black * alpha);
            spriteBatch.DrawString(font, Text, new Vector2(startX, startY).SnapToPixels(), Color.White * alpha);
        }
    }
}
